<?php
namespace core\lib;
use core\lib\log;
/**
 * 控制器基类
 */
class ctrl{

    public $assign = array();
    
    public function assign($name, $value){
        $this->assign[$name] = $value;
    }

    public function display($fileName){
        $file = APP.'/views/'.$fileName;
        if(is_file($file)){
            \Twig_Autoloader::register();
            $loader = new \Twig_Loader_Filesystem(APP.'/views');
            $twig = new \Twig_Environment($loader,array(
                'cache' => KFW.'/log/twig',
                'debug' => DEBUG
            ));
            $template = $twig->loadTemplate($fileName);
            $template->display($this->assign);
        }
    }


    public function beforeAction($action){
        log::log('beforeAction:'.$action);
    }

    public function afterAction($action){
        log::log('afterAction:'.$action);
    }
    /**
     * 重定向
     */
    public function redirect($url){
        header('location:'.$url);
        exit();
    }

    public function renderJSON(){
        
    }
}